home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / c_lib.arc / PCALLOC.C < prev    next >
Text File  |  1990-08-09  |  2KB  |  57 lines

  1. /**
  2. *
  3. *  Name         pcalloc -- Allocate memory
  4. *
  5. *  Synopsis     ercode = pcalloc(request,pseg,psize);
  6. *               int ercode        Returned error code
  7. *               unsigned request  Number of paragraphs requested
  8. *               unsigned *pseg    Segment address of allocated block
  9. *               unsigned *psize   Size in paragraphs of allocated block
  10. *
  11. *  Description  pcalloc allocates a block of memory of request paragraphs
  12. *               (16 bytes).  The next (highest in memory) available block
  13. *               of memory is allocated, and the starting segment address
  14. *               is returned.  If more memory is requested than is available,
  15. *               the amount of available memory is returned, but no block is
  16. *               actually allocated.
  17. *
  18. *  Returns      ercode            Returned DOS 2.0 error code.
  19. *               pseg              Segment address of memory block allocated.
  20. *               psize             Size in paragraphs of memory block which
  21. *                                 is allocated, or the available memory size.
  22. *
  23. *  Version      1.1  (C)Copyright Blaise Computing Inc.  1983, 1984
  24. *
  25. **/
  26.  
  27. struct dreg
  28. {
  29.   unsigned ax,bx,cx,dx,si,di,ds,es;
  30. };
  31.  
  32. int pcalloc(request,pseg,psize)
  33. unsigned request,*pseg,*psize;
  34. {
  35.  
  36.     struct dreg dos_reg;
  37.     int    ercode,dos();
  38.  
  39.     utinit(&dos_reg);                  /* Initialize the registers     */
  40.     dos_reg.ax = 0x4800;
  41.     dos_reg.bx = request;
  42.     ercode     = dos(&dos_reg);        /* Invoke DOS function 48h      */
  43.     *pseg      = 0xffff;               /* Initialize to bad address    */
  44.     if (ercode == 0)
  45.     {
  46.         *pseg  = dos_reg.ax;           /* Segment address              */
  47.         *psize = dos_reg.bx;           /* Segment size                 */
  48.     }
  49.     else if (ercode == 8)
  50.         *psize = dos_reg.bx;           /* Insufficient memory          */
  51.     else
  52.         *psize = 0;
  53.  
  54.     return(ercode);
  55.  
  56. }
  57.